package doyouknow.group.CnAndZhb.controller;

import doyouknow.group.CnAndZhb.entity.TbAdminConfig;
import doyouknow.group.CnAndZhb.entity.TbHotelInfo;
import doyouknow.group.CnAndZhb.error.BusinessException;
import doyouknow.group.CnAndZhb.error.EnumBusinessError;
import doyouknow.group.CnAndZhb.response.BaseControllerReturn;
import doyouknow.group.CnAndZhb.service.TbAdminConfigService;
import doyouknow.group.CnAndZhb.service.TbHotelInfoService;
import doyouknow.group.CnAndZhb.utils.SerializedField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbAdminConfig)表控制层
 *
 * @author cn
 * @since 2020-11-03 21:05:02
 */
@RestController
@RequestMapping("tbAdminConfig")
public class TbAdminConfigController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private TbAdminConfigService tbAdminConfigService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TbAdminConfig selectOne(Integer id) {
        return this.tbAdminConfigService.queryById(id);
    }


    @RequestMapping("/selectOneByAdminId")
    @SerializedField(includes = {"hotelId"})
    //注意includes认实体中的命名而不是数据库里的字段名
    public Object selectOneByAdminId(@RequestParam(defaultValue = "") Integer AdminId) throws BusinessException
    {
        if (StringUtils.isEmpty(AdminId)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_VALIDATION_ERROR,"请输入正确的id");
        }
        List<TbAdminConfig> tbAdminConfigs= tbAdminConfigService.queryByAdminId(AdminId);

        return BaseControllerReturn.create(tbAdminConfigs,null);

    }

}